from wxpyview.ui.component.common.basewidget import *

class Choice(Widget):
    def _getParentParam(self, meta_widget):
        stopping_point = ['Panel']       
        return ComponentLibrary.findFirstMatchedAncestor(meta_widget, stopping_point)
    
    def _setParams(self, meta_widget):
        dom = meta_widget.getDOM()
        if not dom:
            raise IOException
        
        self.params["parent"] = self._getParentParam(meta_widget)
        self.params["id"] = -1
        self.params["pos"] = ComponentLibrary.getPosParam(dom)
        self.params["size"] = ComponentLibrary.getSizeParam(dom)      
        #self.params["style"]
        #self.params["validator"]
        self.params["name"] = dom.getAttribute("name")
        
        # set data for choices
        
        try:
            data = meta_widget.getDataProvider().getData()
            self.params["choices"] = map(lambda x: x["label"], data)
        except: pass
        
    def create(self, meta_widget):
        self._setParams(meta_widget)

        o = wx.Choice(**self.params)
    
        FontProperty.set(meta_widget, o)

        return o